package com.qf.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {

    @Value("${email.emailQueueName}")
    private String emailQueueName;

    @Value("${email.emailExchangeName}")
    private String emailExchangeName;

    @Value("${email.emailRouting}")
    private String emailRouting;

    @Bean
    public TopicExchange emailExchange(){
        return new TopicExchange(emailExchangeName,true,false);
    }

    @Bean
    public Queue emailQueue(){
        return new Queue(emailQueueName,true,false,false);
    }

    @Bean
    public Binding emailQueueBindingExchange(){
        return BindingBuilder.bind(emailQueue()).to(emailExchange()).with(emailRouting);
    }
}
